package ace.tool.generate.code.impl.generator.controller;

import ace.tool.generate.code.impl.generator.AbstractGenerator;
import ace.tool.generate.code.impl.resolver.scheme.EntityClassSchemeResolver;
import ace.tool.generate.code.impl.resolver.scheme.impl.EntityClassSchemeResolverImpl;
import ace.tool.generate.code.impl.resolver.scheme.model.EntityClassSchemeInput;
import ace.tool.generate.code.impl.resolver.scheme.model.EntityClassSchemeModel;
import java.util.List;

/**
 * @author caspar
 * @date 2023/11/17 9:57 spring data jdbc repository 默认架构内容
 */
public class RpcControllerGenerator
    extends AbstractGenerator<RpcControllerGeneratorInput, EntityClassSchemeModel> {

  private final EntityClassSchemeResolver resolver = new EntityClassSchemeResolverImpl();

  @Override
  public void generate(List<RpcControllerGeneratorInput> inputs) {
    inputs.stream().forEach(p -> this.generate(p));
  }

  @Override
  protected EntityClassSchemeModel resolveModel(RpcControllerGeneratorInput input) {

    EntityClassSchemeModel model =
        resolver.resolve(EntityClassSchemeInput.builder().params(input.getParams()).build());

    return model;
  }

  @Override
  protected String getFileName(
      RpcControllerGeneratorInput input, EntityClassSchemeModel schemaModel) {
    return schemaModel.getRestRpcControllerClassName() + ".java";
  }

  @Override
  protected String getFileFullName(
      RpcControllerGeneratorInput input, EntityClassSchemeModel model) {
    String fileName = this.getFileName(input, model);
    String packageFullName = model.getRestRpcControllerPackageFullName();
    String packageFullDirName = packageFullName.replaceAll("\\.", "/");
    return String.format("%s/%s/%s", input.getOutputDir(), packageFullDirName, fileName);
  }
}
